'use strict';
const requireEx=require('yi-require');

const middleware = function(req,res,next){
    let id = req.params.id;
    req.query =  req.query ||{};
    if(req.query.conversationId){
        req.mongo.collection("conversation").update({ _id:req.query.conversationId,lastMessageID:id },{$set:{lastMessageContent:"【最近的消息已被删除】"}},(e,r)=>{
            if(e) return res.err.mongoError(e);
            next();
        });
    }else{
        next();
    }
};

module.exports={
    open:false,
    description:'删除会话',
    middleware:middleware,
    handler:requireEx('yi-restful').d('message',[])
};
